<?php
require_once '../../a_config.php';
require_once "{$A_CONFIG['api_include']}";
require_once '../../api_header.php';
$conn = connect_to_db();
$err = -1;
$msg = "";
$page_num = 10;//每页显示数量
$condition = array();
//phone!="" && name != "" && sex != "" && cla!="" && department !="" && status !="" &&where!="" && brith != "" &&marry!="" && daoban!="" &&both != ""


if (isset($_POST['token']) && !empty($_POST["token"]) &&
    isset($_POST['time']) && !empty($_POST["time"]) &&
    isset($_POST["url"]) && !empty($_POST["url"]) &&
    isset($_POST["url_name"]) && !empty($_POST["url_name"]) &&
    isset($_POST["create_name"]) && !empty($_POST["create_name"]) &&
    isset($_POST["login_id"]) &&
    isset($_POST["passwd"]) &&
    isset($_POST["remark"])

) {
    $key = $A_CONFIG['api_key'];
    $unixtime = $_POST['time'];
    $token = md5($key . $unixtime);
    if ($token == $_POST["token"]) {
        $url = mysql_real_escape_string($_POST["url"]);
        $url_name = mysql_real_escape_string($_POST["url_name"]);
        $create_name = mysql_real_escape_string($_POST["create_name"]);
        $login_id = mysql_real_escape_string($_POST["login_id"]);
        $passwd = mysql_real_escape_string($_POST["passwd"]);
        $remark = mysql_real_escape_string($_POST["remark"]);


        $where = "where is_del=0 and url='$url' limit 1";
        $s_db_name = $A_CONFIG['project_pre'] . '_info';
        $sql = "SELECT id FROM {$s_db_name} $where";
        $res = mysql_query($sql, $conn);
        if (is_resource($res) && mysql_num_rows($res) == 0) {

            $sql = "insert into {$s_db_name} set `url`='$url',`url_name`='$url_name',`create_name`='$create_name',login_name='$login_id',passwd='$passwd'
            ,remark='$remark',create_time= now()";
            $res = mysql_query($sql, $conn);
            if ($res) {
                $msg = "添加成功";
                $err = 0;

            } else {
                $err = -2;
                $msg = "数据处理失败，请重试";
            }


        } else {
            $err = -3;
            $msg = "该url已经存在";
        }
    } else {
        $err = -2;
        $msg = "数据处理失败，请重试";
    }
} else {
    $err = -5;
    $msg = "参数错误";
}
if (!$A_CONFIG['is_debug']) {
    $resArr = compact("err", "msg");
} else {
    $resArr = compact("err", "msg", 'sql');
}
ob_clean();
$resJson = json_encode_cn($resArr);
echo $resJson;